/*
 * ChechCMD.h
 *
 *  Created on: Jun 2, 2011
 *      Author: mahome
 */

#ifndef CHECKCMD_H_
#define CHECKCMD_H_

enum FrameType {
	Ftyp_CMD = 0x0,
	Ftyp_CAK = 0x1,
	Ftyp_CRP = 0x2,
	Ftyp_CRR = 0x3,
	Ftyp_RRR = 0x4,
	Ftyp_ERR = 0x5,
	Ftyp_EVR = 0x6,
	Ftyp_SER = 0x7,
	Ftyp_SRP = 0x8,
	Ftyp_STIM = 0x9,
	Ftyp_FRR = 0xA,
	Ftyp_DAQ = 0xB,
	Ftyp_DRR = 0xC,
	Ftyp_FCF = 0x30,
};

enum ServiceType {
	Styp_SYS = 0x00, //system service
	Styp_CCP = 0x01,
	Styp_UDS = 0x02,
	Styp_OBD = 0x03,
	Styp_MON = 0x05,
	Styp_CFG = 0x07,
	Styp_GPS = 0x08,
	Styp_FLK = 0x09,
	Styp_FUS = 0x0A, //Firmware update service
	Styp_FTS, //file transfer service
	Styp_BMS, //bus monitor service

};

typedef struct Str_CmdPack {
	uword Len;
	ubyte MainCNT;
	ubyte SubCNT;
	ubyte Ftype;
	ubyte Stype;
	uword Source;
	uword Des;
	uword subLen;
} Str_CmdPackHead;

typedef struct Protocol_401_Pack {
	ubyte Len[2];
	ubyte PIDNum[2];
	ubyte Sid;
	ubyte *Data;
} Ptl_401DataHead;
//
typedef struct {
	ubyte pid;
	ubyte* pidp;

}Pid_head;
struct Str_UTPCNT {
	ubyte Main;
	ubyte CA;
	ubyte RB;
	ubyte STM;
	ubyte DAQ;
	ubyte Source;
	ubyte Des;
} UTPRes;

typedef union Long_Byte {
	uint32_t L;
	uint8_t B[4];
} LB;
typedef union Word_Byte {
	uint16_t W;
	uint8_t B[4];
} WB;
extern ubyte Pos_SID;
extern Str_CmdPackHead* CmdHead;
extern Str_CmdPackHead SysConfigServ;
extern Str_CmdPackHead CcpServ;
extern Str_CmdPackHead ISOServ;
extern Str_CmdPackHead Firmware;
extern Str_CmdPackHead Monitor;
extern ubyte Public_Ip_Num;

extern ubyte RS_Cmd[Len_Inbuff];
extern LB CmdLB;
extern WB CmdWB;
extern ubyte ResponseServer_PackageBuf[Big_SIZE];
extern ubyte GeneralBuf[Big_SIZE];
extern ubyte CheckSumReturnUByte(ulong Num, ubyte* StardAdd);
extern ubyte SetIP_Num(ubyte num);
extern ubyte GetIP_Num(void);

extern uint16_t PPP_Pack(uint8_t SendBuf[], uint16_t maxLen, uint16_t *useLen);
extern uint16_t PPP_UnPack(uint8_t RevBuf[], uint16_t maxLen, uint16_t *useLen);
extern void General_Respone2Server(ubyte* data, uword dataLen); //,ubyte MCNT, ubyte SubCNT,ubyte Ftype, ubyte Stype ,uword Src,uword Des);
extern void thrRB_CmdExtract(void const *argument);
#endif /* CHECKCMD_H_ */
